1

00:00:01,380  -->  00:00:08,080
In the previous video we learn how to configure
ssh on cisco routers and mikrotik routers.

2

00:00:08,560  -->  00:00:15,800
So now, we can remote the cisco and mikrotik
router from our computer using ssh.

3

00:00:16,420  -->  00:00:24,640
Well, in this video we will learn how to do
network automation, we will learn about network

4

00:00:24,640  -->  00:00:27,460
automation on cisco routers first.

5

00:00:28,000  -->  00:00:33,600
We will learn about network automation on
mikrotik routers in the next video.

6

00:00:33,920  -->  00:00:41,100
Okay, let's get to the point, this is the
script that we will use in this video

7

00:00:41,420  -->  00:00:45,440
which is to do network automation on cisco routers.

8

00:00:45,480  -->  00:00:53,500
I will also upload this script to the resources
section, so you can download it, but I recommend

9

00:00:53,500  -->  00:00:59,940
you to not copy and paste the code, you need
to write the code by your self, so you can

10

00:00:59,940  -->  00:01:02,400
understand the code easily.

11

00:01:02,400  -->  00:01:10,520
Let’s understand the code, in the first
line, we import paramiko, paramiko is python

12

00:01:10,520  -->  00:01:14,620
library that we are going to use as a ssh
client.

13

00:01:15,300  -->  00:01:22,820
We also need to import time, I will explain
later why we need to import time.

14

00:01:22,820  -->  00:01:29,080
Here we define the ip address, username and
password of the cisco router

15

00:01:29,340  -->  00:01:32,600
We call SSH Client function from paramiko.

16

00:01:34,180  -->  00:01:39,820
Then we connect to the router using the ip
address, username, and password that we have

17

00:01:39,880  -->  00:01:41,760
defined before.

18

00:01:44,240  -->  00:01:51,860
Here, we print that we have successfully connected
to the router, and then do invoke shell.

19

00:01:52,240  -->  00:01:56,520
Here we can see that we send the cisco command
to the router.

20

00:01:56,700  -->  00:02:05,260
In this example I just send a command to configure
loopback interface 0 with ip address 10.1.1.1.

21

00:02:05,260  -->  00:02:11,940
Here you can see that I define time sleep
1, which means that the code will delay for

22

00:02:11,940  -->  00:02:18,440
1 seconds, we need to make the code wait for
1 seconds or the command will not sent to

23

00:02:18,440  -->  00:02:25,900
the router successfully, we will try to remove
the time sleep later and we will see the result.

24

00:02:25,900  -->  00:02:32,780
Here we save the output of the cisco command
that we have sent to the router

25

00:02:34,020  -->  00:02:37,640
and then we print the output to the console.

26

00:02:37,640  -->  00:02:41,880
Last, we need to close the ssh connection
from the router.

27

00:02:42,420  -->  00:02:45,680
Okay Now let’s run the code.

28

00:02:45,680  -->  00:02:51,440
open the command prompt, and go to the directory
where we save the code.

29

00:02:53,660  -->  00:02:58,880
Let’s try to dir to make sure that we are
in the right directory.

30

00:02:58,880  -->  00:03:02,380
Here we can see that we have script.py.

31

00:03:02,900  -->  00:03:07,640
Let’s run the code by command python script.py

32

00:03:11,980  -->  00:03:19,640
Here we can see that we have successfully
login to 192.168.1.3, which is the IP Address

33

00:03:19,640  -->  00:03:21,540
of Cisco Router.

34

00:03:21,540  -->  00:03:28,000
And then we also see that we have successfully
send command to configure loopback interface

35

00:03:28,000  -->  00:03:32,800
0 with ip address 10.1.1.1 to the cisco router.

36

00:03:33,620  -->  00:03:42,060
Let’s go to the cisco router and type show
ip interface brief

37

00:03:44,720  -->  00:03:51,940
here we can see that now we have loopback 0 with ip address 10.1.1.1.

38

00:03:51,940  -->  00:03:53,760
Congratulations!

39

00:03:53,760  -->  00:03:57,840
You are successfully doing your first Network
Automation!

40

00:03:58,200  -->  00:04:05,460
Last for this video, I want to show you how
if I remove the time sleep from the code.

41

00:04:06,480  -->  00:04:09,020
Here remove time sleep.

42

00:04:09,900  -->  00:04:14,040
I will change the loopback interface and
the ip address,

43

00:04:16,340  -->  00:04:23,000
Now save the code, and run it again.

44

00:04:29,580  -->  00:04:37,080
Look, the command is not sent to the router
successfully, let’s go to the cisco router

45

00:04:39,640  -->  00:04:46,400
and type show ip interface brief, we also
not see the interface loopback 1 here.

46

00:04:46,400  -->  00:04:50,700
Now let’s put the time sleep again to the
code.

47

00:04:50,700  -->  00:04:58,820
Save the code, And run it again.

48

00:05:01,580  -->  00:05:08,160
Cool !  the command sent to the router successfully,
let’s make sure again in the cisco router,

49

00:05:13,940  -->  00:05:20,180
now we have interface loopback 1 with IP Address
10.1.1.2 here

50

00:05:20,500  -->  00:05:27,600
Congratulation !  now you are able to write a
simple script for network automation on cisco router

51

00:05:27,920  -->  00:05:34,380
In the next video, we are going to learn simple
script for network automation on mikrotik router

52

00:05:34,700  -->  00:05:38,540
Thankyou for watching and See you on the next
video.
